package de.lns.entities.ai;

import de.lns.entities.mobs.Mob;
import de.lns.tick.UpdateThread;
/**
 * 
 * @author Frederick Hastedt, Vincent
 *
 */
public class Standardmobai extends Mobai {
	/**
	 * point: determines which pathpoint the mobs are at
	 * hypotenuseLength: the length of the distance between the mob and the next pathpoint
	 */
	private int point = 0;
	private double xDiff = 0;
	private double yDiff = 0;
	private double hypotenuseLength = 0;
	private double travelDistance = 0;
	private boolean ending = false;
	
	
	/**
	 * 
	 * @param mob: mob object
	 */
	public Standardmobai(Mob mob) {
		super(mob); 
	}
	/**
	 * method to move the mob
	 */
	@Override
	public void move() {
		
		travelDistance = mob.getMovementspeed()*UpdateThread.getDelta()/1000;
		
		while(travelDistance > 0){
			xDiff = mob.getPath()[point] - mob.getPosX();
			yDiff = mob.getPath()[point + 1] - mob.getPosY();
			hypotenuseLength = Math.hypot(xDiff, yDiff);
			if(travelDistance >= hypotenuseLength){
				mob.setPosX(mob.getPath()[point]);
				mob.setPosY(mob.getPath()[point + 1]);
				if(ending){
					mob.accomplished();
					return;
				} else{
					point += 2;
					if(point == mob.getPath().length-2){
						ending = true;
					}
					travelDistance -= hypotenuseLength;
				}
			} else{
				//mob.setDirection(Math.asin(xDiff/hypotenuseLength));
				mob.setPosX(mob.getPosX() + ((xDiff/hypotenuseLength)*travelDistance));
				mob.setPosY(mob.getPosY() + ((yDiff/hypotenuseLength)*travelDistance));
				return;
			}
		}
	}

	public void checkNextPoint() {
		
	}

}
